﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace Pavilion.Communications
{
    public class DesignerService : IDesignerService
    {
        public bool IsTransferring { get; private set; }
        public Action<string, string, List<string>, string> NodeLoadedAction { get; set; }
        public Action<string, string, List<string>, string> NodeUnloadedAction { get; set; }
        public Action DisableAllCurrentlyPlayingNodesAction { get; set; }

        public void RequestDataTransfer()
        {
            DataTransferClient.Instance.FullDataTransfer();
        }

        public void DisableAllCurrentlyPlayingNodes()
        {
            if (DisableAllCurrentlyPlayingNodesAction == null)
                return;

            DisableAllCurrentlyPlayingNodesAction.Invoke();
        }

        public void NodeLoaded(string resourceName, string scriptName, List<string> containerNodeNameList, string nodeName)
        {
            if (NodeLoadedAction == null)
                return;

            NodeLoadedAction.Invoke(resourceName, scriptName, containerNodeNameList, nodeName);
        }

        public void NodeUnloaded(string resourceName, string scriptName, List<string> containerNodeNameList, string nodeName)
        {
            if (NodeUnloadedAction == null)
                return;

            NodeUnloadedAction.Invoke(resourceName, scriptName, containerNodeNameList, nodeName);
        }
    }

    [ServiceContract()]
    public interface IDesignerService : ITransferringService
    {
        [OperationContract]
        void RequestDataTransfer();
        [OperationContract]
        void DisableAllCurrentlyPlayingNodes();
        [OperationContract]
        void NodeLoaded(string resourceName, string scriptName, List<string> containerNodeNameList, string nodeName);
        [OperationContract]
        void NodeUnloaded(string resourceName, string scriptName, List<string> containerNodeNameList, string nodeName);
    }

    public interface ITransferringService
    {
        bool IsTransferring { get; }
    }
}
